home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / malloc15.zip / TEST.C < prev   
Text File  |  1996-04-17  |  2KB  |  86 lines

  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include "mem.h"
  4.  
  5. main()
  6. {
  7.     char *foo = "hello";
  8.     char *s, *t;
  9.     printf("hello, world\n");
  10.     free(foo);
  11.  
  12.     s = malloc(10);
  13.     strcpy(s, foo);
  14.     s = realloc(s, 6);
  15.     puts(s);
  16.  
  17.     s = malloc(10);
  18.     t = malloc(10);
  19.     memcpy(s, t, 11);
  20.     s = malloc(20);
  21.     memcpy(s, t, 11);
  22.     s = strdup("foo");
  23.     memcpy(s, t, 11);
  24.     s = realloc(s, 6);
  25.     memcpy(s, t, 21);
  26.     sprintf(s, "1234567890 %s ", "hello");
  27.     free(s);
  28.     free(t);
  29.     return(0);
  30. }
  31. From hornen@hlbjoan.agw.bt.co.uk Wed Apr 17 18:07:44 1996
  32. Received: from punt2.demon.co.uk by smsltd.demon.co.uk with SMTP
  33.     id AA12820 ; Wed, 17 Apr 96 18:07:40 BST
  34. Received: from punt-2.mail.demon.net by mailstore for njh@smsltd.demon.co.uk
  35.           id 829733659:22996:2; Wed, 17 Apr 96 10:34:19 BST
  36. Received: from mailhub.axion.bt.co.uk ([132.146.5.4]) by punt-2.mail.demon.net
  37.           id aa22677; 17 Apr 96 10:33 +0100
  38. Received: from catullus.agw.bt.co.uk by mailhub.axion.bt.co.uk with SMTP (PP); Wed, 17 Apr 1996 10:31:49 +0100
  39. Received: from isdgate.agw.bt.co.uk (isdgate.agw.bt.co.uk [147.150.41.229]) by catullus.agw.bt.co.uk (8.6.12/8.6.11) with SMTP 
  40.           id KAA25209 for <njh@smsltd.demon.co.uk>; Wed, 17 Apr 1996 10:35:01 +0100
  41. Received: by isdgate.agw.bt.co.uk with Microsoft Mail id <3174C7E2@isdgate.agw.bt.co.uk>; Wed, 17 Apr 96 10:28:50 GMT
  42. From: "Horne, Nigel" <hornen@hlbjoan.agw.bt.co.uk>
  43. To: NJH <njh@smsltd.demon.co.uk>
  44. Subject: TEST.C
  45. Date: Wed, 17 Apr 96 10:23:00 GMT
  46. Message-ID: <3174C7E2@isdgate.agw.bt.co.uk>
  47. Encoding: 3 TEXT, 1 TEXT
  48. X-Mailer: Microsoft Mail V3.0
  49. X-MS-Attachment: TEST.C 595 04-17-1996 09:46
  50. Status: R
  51.  
  52.  
  53. [[ TEST.C : 2373 in TEST.C ]]
  54.  
  55.  
  56. #include <stdio.h>
  57. #include <malloc.h>
  58. #include "mem.h"
  59.  
  60. main()
  61. {
  62.         char *foo = "hello";
  63.         char *s, *t;
  64.         printf("hello, world\n");
  65.         free(foo);
  66.  
  67.         s = malloc(10);
  68.         strcpy(s, foo);
  69.         s = realloc(s, 6);
  70.         puts(s);
  71.  
  72.         s = malloc(10);
  73.         t = malloc(10);
  74.         memcpy(s, t, 11);
  75.         s = malloc(20);
  76.         memcpy(s, t, 11);
  77.         s = strdup("foo");
  78.         memcpy(s, t, 11);
  79.         s = realloc(s, 6);
  80.         memcpy(s, t, 21);
  81.         sprintf(s, "1234567890 %s ", "hello");
  82.         free(s);
  83.         free(t);
  84.         return(0);
  85. }
  86.